package com.yywq.controller;

import com.yywq.error.BusinessException;
import com.yywq.error.EnumBusinessError;
import com.yywq.pojo.view.OrderView;
import com.yywq.response.CommonReturnType;
import com.yywq.service.impl.OrdersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: 吴磊
 * @program: yywq_parent
 * @create: 2021-04-15 14:59
 */
@RestController
@RequestMapping("/order")
public class OrdersController {

    @Autowired
    private OrdersServiceImpl ordersService;

    /**
     * 查询买家的订单
     *
     * @param bid
     * @return
     */
    @RequestMapping(value = "/getOrderWithBid", method = RequestMethod.POST)
    private CommonReturnType getBuyOrders(@RequestParam("bid") String bid) {
        if (StringUtils.isEmpty(bid)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_INVALID_ERROR);
        }
        List<OrderView> orderByBid = ordersService.getOrderByBid(bid);
        return CommonReturnType.create(orderByBid);
    }

    /**
     * 查询卖家的订单
     *
     * @param sid
     * @return
     */
    @RequestMapping(value = "/getOrderWithSid", method = RequestMethod.POST)
    private CommonReturnType getSaleOrders(@RequestParam("sid") String sid) {
        if (StringUtils.isEmpty(sid)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_INVALID_ERROR);
        }
        List<OrderView> orderBySid = ordersService.getOrderBySid(sid);
        return CommonReturnType.create(orderBySid);
    }

}
